﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DAL_OrderDetail
/// </summary>
public class DAL_OrderDetail
{
    DbProvider db = new DbProvider();

    public void OrderDetail_Insert(DTO_OrderDetail obj)
    {

        string sql = string.Format("INSERT INTO [OrderDetail] VALUES (N'{0}',N'{1}',N'{2}')", obj.Order_Id, obj.Product_Id, obj.Quantily);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }
    public void OrderDetail_UpdateByAll(string Id, DTO_OrderDetail obj)
    {

        string sql = string.Format("UPDATE [OrderDetail] SET [Order_Id] = '{0}',Product_Id = '{1}',[Quantily] = '{2}' WHERE [Id] = '{3}'", obj.Order_Id, obj.Product_Id, obj.Quantily, Id);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }

    public void OrderDetail_UpdateBySet(string Id, string Set)
    {

        string sql = string.Format("UPDATE [OrderDetail] SET {0} WHERE [Id] = '{1}'", Set, Id);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }
    public void OrderDetail_Delete(string Id)
    {

        string sql = string.Format("DELETE FROM OrderDetail WHERE Id = '{0}'", Id);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }

    public DataTable OrderDetail_GetByAll(int Status)
    {
        DataTable dt = new DataTable();
        string sql = string.Format("select * from OrderDetail where [Status]= '{0}' ", Status);
        try
        {
            dt = db.ExecuteQuery(sql);

        }
        catch (Exception)
        {

            throw;
        }
        return dt;
    }
    public DataTable OrderDetail_GetByTop(int top, string where, string order)
    {
        DataTable dt = new DataTable();
        //string sql = string.Format("select top {0} * from Product where = '{1}' Order by [{2}] DESC,[Order]", top, where,order);
        string sql = "";
        if (top <= 0)
        {
            sql += "SELECT * FROM OrderDetail";
        }
        else
        {
            sql += "SELECT TOP " + top + " * FROM OrderDetail";
        }
        if (where != "")
        {
            sql += " WHERE " + where;
        }
        if (order != "")
        {
            sql += " Order by " + order;
        }
        try
        {
            dt = db.ExecuteQuery(sql);

        }
        catch (Exception)
        {

            throw;
        }
        return dt;
    }
    public DataTable OrderDetail_GetByID(string id)
    {
        DataTable dt = new DataTable();
        string sql = string.Format("select * from OrderDetail where Id = {0}", id);
        try
        {
            dt = db.ExecuteQuery(sql);

        }
        catch (Exception)
        {

            throw;
        }
        return dt;
    }

}